<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>设备管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../js/lib/layui/dist/css/layui.css">
</head>
<body>
<table id="task-list" lay-filter="task-list"></table>
<script type="text/html" id="barDemo">
    {{# if(d.status == 'end'){ }}
        <a href="{{d.downloadfile}}" download="{{d.downloadfilename}}"><span class="layui-icon">&#xe601;下载</span></a>
    {{# } else if(d.status == 'monkeytesting') { }}
        <a class="layui-btn layui-btn-xs" lay-event="terminate"><span class="layui-icon">&#x1007;中止</span></a>
    {{# } }}
    <!--<a href="{{d.downloadfile}}" download="{{d.downloadfilename}}"><span class="layui-icon">&#xe60b;</span></a>-->
</script>
<script src="../js/lib/jquery/dist/jquery.min.js"></script>
<script src="../js/lib/PACE/pace.min.js"></script>
<script src="../js/lib/lodash/dist/lodash.min.js"></script>
<script src="../js/lib/layui/dist/layui.js"></script>

<script>
            //JavaScript代码区域
            layui.use(['form', 'laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function () {
                // var form = layui.form;
                // var $ = layui.$;

                var table = layui.table;
                table.render({
                    elem: '#task-list'
                    //, height: 800
                    , url: '/task/task_monkey_lisk'
                    // , page: true
                    , cols: [[
                        {field: 'date', title: '日期', width: 110 }
                        //,{field: 'sup_task_name', title: '任务名', width:300}
                        //,{field: 'sub_task_name', title: '子任务名', width:400}
                        ,{field: 'product_of_device', title: '设备信息', width:350}
                        ,{field: 'status', title: '任务状态', width:150}
                        ,{field: 'sup_task_name', title: '父任务', width:100}
                        ,{field: 'sub_task_name', title: '子任务'}
                        ,{fixed: 'right', title: '操作', width: 280, align:'center', toolbar: '#barDemo'}
                        //,{field: 'done', title: '任务状态', width:70}
                        // ,{field: 'area', title: '区域', width: 60}
                        // ,{field: 'build_if', title: '？B', width: 60}
                        // ,{field: 'monkey_test_if', title: '？M', width: 60}
                        // ,{field: 'monkey_cmd', title: 'monkey指令'}
                        // ,{field: 'execpolicy', title: '执行策略', width: 90}
                        // ,{field: 'weekdays', title: '周执行计划', width:120}
                        // ,{field: 'iter_time', title: '每天时段', width: 150}
                        // ,{field: 'long_time', title: '单次时长', width: 90}
                        // ,{field: 'point_time', title: '开始时间'}
                    ]]
                });

                table.on('tool(task-list)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                    var data = obj.data //获得当前行数据
                    ,layEvent = obj.event; //获得 lay-event 对应的值
                    console.log(data)
                    if(layEvent === 'terminate'){
                        layer.msg('terminate task');
                        $.ajax({
                            url: baseurl + "/task/terminate/" + data.date + "_" + data.pid,
                            type: 'get',
                            dataType: 'json',
                            async: false,
                            // xhrFields: {
                            //     withCredentials: true
                            // },
                            crossDomain: true,
                            success: function (res) {
                                console.log(res);
                            }
                        });
                    } else if(layEvent === 'del'){
                        layer.confirm('真的删除行么', function(index){
                        obj.del(); //删除对应行（tr）的DOM结构
                        layer.close(index);
                        //向服务端发送删除指令
                        });
                    } else if(layEvent === 'edit'){
                        layer.msg('编辑操作');
                    }
                });

            });

</script>
</body>
</html>
